package cn.bmbanjia.zebra2024.apps.openapi.controller;

import cn.bmbanjia.zebra2024.aliyuncloud.rocketmq.producer.BmbjProducerDelayMessage;
import cn.bmbanjia.zebra2024.apps.openapi.req.ClewDelayMessageReq;
import cn.bmbanjia.zebra2024.apps.openapi.req.SendTtsVoiceReq;
import cn.bmbanjia.zebra2024.frame.resp.Resp;
import cn.bmbanjia.zebra2024.tencentcloud.TencentCloudVMS;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.JSONUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/openapi")
@Tag(name = "openapi")
@Slf4j
public class OpenApiController {

    @Operation(summary = "clewDelayMessage")
    @PostMapping("/clewDelayMessage")
    public Resp<Void> clewDelayMessage(@RequestBody @Valid ClewDelayMessageReq req) {
        BmbjProducerDelayMessage.sendBmbjClewDelayMessage(JSONUtil.toJsonStr(req).getBytes(StandardCharsets.UTF_8));
        return Resp.success();
    }

    @Operation(summary = "sendTtsVoice")
    @PostMapping("/sendTtsVoice")
    public Resp<Void> sendTtsVoice(@RequestBody @Valid SendTtsVoiceReq req) {
        String[] args = new String[]{};
        if (ObjUtil.isNotEmpty(req.getTemplateParams())) {
            args = req.getTemplateParams().toArray(args);
        }
        TencentCloudVMS.sendTtsVoice(req.getVoiceSdkAppid(), req.getCalledNumber(), req.getTemplateId(), args);
        return Resp.success();
    }

}
